// const { gotoJiudian } = require("../../utils/util")


Page({

    /**
     * 页面的初始数据
     */
    data: {
        // types: 'jiudian',
        currenttab: '0',
        weizhi_imgUrl: '/icon/weizhi.png',
        path_imgUrl: '/icon/path.png',
        pinglun_name: '李艳梅',
        pinglun_face: '/icon/touxiang.png',
        pinglun_imgUrl: '/icon/pinglun.png',
        pinglun_con: '推荐去!'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //获取rim.js界面传来的index,info
        this.setData({
            city: getApp().data.localCity,
            index: options.index,  //info模块内点击的卡片的index
            info: options.info,   //模块名
            type: options.type,  //类别区分
            name: options.name,  //景区名字
            types: options.info
        })

        // 区分推荐类型
        if (this.data.info == 'tuijian') {
            switch (this.data.type) {
                case '1':
                    this.setData({
                        types: 'jingdian'
                    })
                    break;
                case '2':
                    this.setData({
                        types: 'meishi'
                    })
                    break;
                case '3':
                    this.setData({
                        types: 'jiudian'
                    })
                    break;
            }
            const that = this
            console.log(this.data.type);
            console.log(this.data.city)
            console.log(this.data.name)
            wx.request({
                url: `https://wx.qasdwer.top:2001/recommend_detail?type=${this.data.type}&city=${this.data.city}&name=${this.data.name}`,
                method: 'GET',
                dataType: 'json',
                success: res => {
                    // console.log(res);
                    console.log('1:', res.data[0]);
                    this.setData({
                        list: res.data[0]
                    })
                    // 历史记录
                    console.log('3', getApp().data.list)
                    console.log('this.data.list.placeName', this.data.list.placeName || this.data.list.foodName || this.data.list.pubName)
                    let name = (this.data.list.placeName || this.data.list.foodName || this.data.list.pubName)
                    //若历史记录中没有该条记录，添加进历史记录列表
                    let a = getApp().data.list.filter(item=>name== (item.placeName || item.foodName|| item.pubName))
                    console.log('222', a)
                    if (a == '') {
                        getApp().data.list.unshift(this.data.list);
                    }

                    // 美食详情模块 推荐菜
                    if (this.data.type == 2) {
                        let a = this.data.list.foodRecom;
                        let a1 = a.substring(1, a.length - 1)
                        let b = a1.split(',')
                        for (let i = 0; i < b.length; i++) {
                            b[i] = `(${i + 1})` + b[i].substring(1, b[i].length - 1)
                        }
                        this.setData({
                            foodRecom: b
                        })
                    }

                }
            })
        } else {
            // 景点，美食，酒店请求
            wx.request({
                url: `https://wx.qasdwer.top:2001/rim_detail?info=${this.data.info}&city=${this.data.city}&index=${this.data.index}`,
                method: 'GET',
                dataType: 'json',
                success: res => {
                    var data = res.data[0]
                    console.log('1', res.data[0])
                    this.setData({
                        list: data
                    })
                    // 历史记录
                    let name = (this.data.list.placeName || this.data.list.foodName || this.data.list.pubName)
                    //若历史记录中没有该条记录，添加进历史记录列表
                    let a = getApp().data.list.filter(item=>name== (item.placeName || item.foodName|| item.pubName))
                    console.log('222', a)
                    if (a == '') {
                        getApp().data.list.unshift(this.data.list);
                    }

                    // 美食详情模块 推荐菜
                    if (this.data.info == 'meishi') {
                        let a = this.data.list.foodRecom;
                        let a1 = a.substring(1, a.length - 1)
                        let b = a1.split(',')
                        for (let i = 0; i < b.length; i++) {
                            b[i] = `(${i + 1})` + b[i].substring(1, b[i].length - 1)
                        }
                        this.setData({
                            foodRecom: b
                        })
                    }
                },
                fail: error => {
                    console.log(error)
                }
            })
        }



    },

    gotoRoute: function () {
        let endPoint
        let plugin = requirePlugin('routePlan');
        let key = 'HBABZ-QF7RX-C2S4W-TOZ4R-EQP66-UMB5X';
        let referer = 'i行亦知';   //调用插件的app的名称
        // console.log('122',this.data.info,this.data.type)
        if (this.data.info == 'tuijian' && this.data.type == 1) {
            console.log('1111')
            this.endPoint = JSON.stringify({  //终点
                'name': this.data.name,
                'latitude': this.data.list.latitude,
                'longitude': this.data.list.longitude
            });
        } else if (this.data.info == 'jingdian') {
            console.log('2222')
            this.endPoint = JSON.stringify({  //终点
                'name': this.data.list.placeName,
                'latitude': this.data.list.latitude,
                'longitude': this.data.list.longitude
            });
        }
        console.log(this.endPoint)

        wx.navigateTo({
            url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + this.endPoint
        });
    },

   
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */


    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})